{extend name="platform/base" /}
{block name="resources"/}
<script type="text/javascript" src="__STATIC__/My97DatePicker/WdatePicker.js"></script>
<style>
.set-style dl:after{
	content:'';
	display:block;
	height:0px;
	clear:both;
}
.set-style dl dt{
	display:block;
	width:20%;
	float:left;
	text-align:right;
}
.set-style dl dd{
	display:block;
	width:80%;
	float:left;
}
.set-style dl dd textarea{
	font-size: 12px;
    color: #777;
    background-color: #FFF;
    vertical-align: top;
    display: inline-block;
    height: 60px;
    padding: 4px;
    border: solid 1px #CCC;
    outline: none;
    width: 400px;
    margin: 0;
}
.textarea-common{
	border-radius: 0 !important;
    resize: none !important;
    width: 250px !important;
    box-sizing: border-box !important;
}
</style>
{/block}
 {block name="main"}
<div class="row padder-v">
	<div class="col-sm-3">
		
	</div>
	
	<div class="col-sm-2 js-shop-block" >
		<input type="text" id="member_name" class="input-sm form-control" placeholder="请输入用户名称"> 
	</div>
	<div class="col-sm-2 js-shop-block" >
		<select class="input-sm form-control" id="explain_type" >
			<option value="">评价类型</option>
			<option value="">全部</option>
			<option value="1">好评</option>
			<option value="2">中评</option>
			<option value="3">差评</option>
       </select>	
	</div>
	<div class="col-sm-2 js-shop-block" >
		<input type="text" id="startDate" placeholder="请选择开始日期" class="input-sm form-control" onclick="WdatePicker()">
	</div>
	<div class="col-sm-2 js-shop-block" >
		<input type="text" id="endDate" placeholder="请选择结束日期" class="input-sm form-control" onclick="WdatePicker()">
	</div>
	<div class="col-sm-1">
		<button class="btn btn-sm btn-default" type="button" onclick="LoadingInfo(1)">搜索</button>
	</div>
</div>
<section class="panel panel-default">
	<div class="table-responsive">
		<table class="table table-striped b-light text-sm">
			<colgroup>
				<col style="width: 2%;">
				<col style="width: 14%;">
				<col style="width: 30%;">
				<col style="width: 19%;">
				<col style="width: 25%;">
				<col style="width: 10%;">
			</colgroup>
			<thead>
				<tr>
					<th><input type="checkbox"></th>
					<th colspan="2">商品</th>
					<th>评价信息</th>
					<th class="center">评价时间</th>
					<th class="center">操作</th>
				</tr>
			</thead>
			<tbody id="list">
				
			</tbody>
		</table>
	</div>
	
	<!-- 评价回复 -->
	<input type="hidden" id="type">
	<input type="hidden" id="replyType">
	<div class="modal fade" id="evaluate">
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal"
						aria-hidden="true">&times;</button>
					<h4 class="modal-title" id="myModalLabel">评价回复</h4>
				</div>
				
				<div class="modal-body">
					<div class="set-style">
						<dl>
							<dt id="myModaltype">评价内容：</dt>
							<dd id="evaluate_content">
							</dd>
						</dl>
						<dl>
							<dt id="reply">回复内容：</dt>
							<dd>
								<textarea id="evaluate_reply"  class="textarea-common"></textarea>
							</dd>
						</dl>
					</div>
				</div>
				
				<div class="modal-footer">
					<input type="hidden" id="evaluate_id">
					<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
					<button type="button" class="btn btn-info" onclick="replyevaluateAjax()">确定</button>
				</div>
			</div>
		</div>
	</div>	
	
	{include file="platform/page" /}
</section>
{/block} 
{block name="script"}
<link rel="stylesheet" type="text/css" href="__ROOT__/public/admin/css/plugin/jquery.searchableSelect.css">
<script src="__ROOT__/public/admin/js/plugin/jquery.searchableSelect.js"></script>
<script src="__STATIC__/js/BootstrapMenu.min.js"></script>

<script type="text/javascript">

	$(function(){
		LoadingInfo(1);
	});

	//查询用户列表
	function LoadingInfo(pageIndex) {
		
		var shop_id = $("#shop_id").val();
		var member_name = $("#member_name").val();
		var start_date = $("#startDate").val();
		var end_date = $("#endDate").val();
		var explain_type = $("#explain_type").val();
		$.ajax({
			type : "post",
			url : "{:__URL('PLATFORM_MAIN/goods/goodscomment')}",
			async : true,
			data : {
				"shop_id" : shop_id, 
				"page_index" : pageIndex,
				"start_date":start_date,
				"end_date":end_date,
				"member_name" : member_name,
				"explain_type" : explain_type
			},
			success : function(data) {
				console.log(data);
				var html = '';
				$("#total_count_num").text(data["total_count"]);
				$("#page_count_num").text(data["page_count"]);
				$("#page_count").val(data["page_count"]);
				$("#pageNumber a").remove();
				
				if (data["data"].length > 0) {
					
					for (var i = 0; i < data["data"].length; i++) {
						
						html += '<tr class="tr-title">';
						if(data['data'][i]['again_content'].length > 0){
							html += '<td style="text-align:center;" rowspan="3">';
						}else{
							html += '<td style="text-align:center;" rowspan="2">';
						}
						
						html += '<i class="checkbox-common"><input value="'+data['data'][i]['id']+'" name="sub" type="checkbox"></i></td>';
						html += '<td colspan="2" style="padding-left:35px;border-left:1px solid #e5e5e5;"><div class="pro-code"><a href="'+__URL('SHOP_MAIN/goods/goodsinfo?goodsid='+data["data"][i]["goods_id"])+'" target="_blank">';
						html += '<span style="margin-right:5px;width:60px;float:left;"><img src="'+ __IMG(data["data"][i]["goods_image"])+'" style="width:60px;height:60px;"></span>';
						html += '<span>商品名称：'+ data["data"][i]["goods_name"]+'</span><br/>';
						html += '<span>店铺名称：'+ data["data"][i]["shop_name"]+'</span>';
						html += '</a></div></td>';
						html += '<td><span class="pro-code">评价用户： '+ data["data"][i]["member_name"]+'</span><br><span class="pro-code" >';
						switch(data["data"][i]["explain_type"]){
							case 1:
								html += '用户评价： 好评</span><br>';
								break;
								case 2:
								html += '用户评价： 中评</span><br>';
								break;
								case 3:
								html += '用户评价： 差评</span><br>';
							break;
						}
						html += '<span class="pro-code">用户评分： '+ data["data"][i]["scores"]+'分</span></td>';
						html += '<td align="center"><span class="pro-code">评价时间：'+ timeStampTurnTime(data["data"][i]["addtime"])+'</span></td>';
						if(data['data'][i]['is_show'] == 1){
							html += '<td style="text-align:center;"><a href="javascript:;" title="点击隐藏" onclick="setEvaluteShowStatuAjax('+data['data'][i]['id']+');">隐藏</a>';
							html += '<a href="javascript:void(0)" data-placement="bottom" onclick="deleteEvaluate('+data['data'][i]['id']+')" data-original-title="删除"><span class="del" style="display: inline-block;"><i class="icon-trash" style="width: initial;"></i>删除</span></a></td></tr>';
						}else{
							html += '<td style="text-align:center;"><a href="javascript:;" title="点击显示" onclick="setEvaluteShowStatuAjax('+data['data'][i]['id']+');">显示</a>';
							html += '<a href="javascript:void(0)" data-placement="bottom" onclick="deleteEvaluate('+data['data'][i]['id'] +')" data-original-title="删除"><span class="del" style="display: inline-block;"><i class="icon-trash" style="width: initial;"></i>删除</span></a></td></tr>';
						}
						html += '<tr><td colspan="4" style="background: white;"><p><span class="content-left">评价内容:</span>';
						if(data['data'][i]['content'].length > 0){
							html +='<span class="evaluate_content content">'+data['data'][i]['content']+'</span>';
							if(data['data'][i]['image']!= ''){
								var imgs_arr=data['data'][i]['image'].split(',');
								html += '<span class="evaluate_content content" style="margin-left: 65px;margin-top: 5px;">';
								for(var key in imgs_arr){
									html += '<img src="'+__IMG(imgs_arr[key])+'" alt="" style="max-height:60px;margin-right:10px;">';
								}
								html += '</span></p>';
							}
						}else{
							html += '<span class="evaluate_content"></span><br></p>';
						}	
						if(data['data'][i]['explain_first'].length > 0){
							html += '<p><span class="content-left">回复内容:</span> <span class="evaluate_reply content">'+data['data'][i]['explain_first']+'</span></p></td>';
							html += '<td style="background: white;"><div class="bs-docs-example tooltip-demo" style="text-align: center;"><a href="javascript:;" data-placement="bottom" data-original-title="回复"><span class="edit" onclick="replyevaluate('+data['data'][i]['id'] +',this)"><i class="icon-edit" style="width: initial;"></i>回复</span></a></div></td></tr>';
						}else{
							html += '<td style="background: white;"><div class="bs-docs-example tooltip-demo" style="text-align: center;"><a href="javascript:;" data-placement="bottom" data-original-title="回复"><span class="edit" onclick="replyevaluate('+data['data'][i]['id'] +',this)"><i class="icon-edit" style="width: initial;"></i>回复</span></a></div></td></tr>';
						}
						if(data['data'][i]['again_content'].length > 0){
							html += '<tr><td colspan="4" style="background: white;"><p><span  class="content-left">追评内容:</span>';
							html +='<span class="evaluate_content content">'+data['data'][i]['again_content']+'</span>';
							if(data['data'][i]['again_image'].length > 0){
								var imgs_arr=data['data'][i]['again_image'].split(',');
								html += '<span class="evaluate_content" style="margin-left: 65px; margin-top: 5px;display:block;">';
								for(var key in imgs_arr){
									html += '<img src="'+__IMG(imgs_arr[key])+'" alt="" style="max-height:60px;margin-right:10px;">';
								}
								html += '</span></p>';
							}
							if (data['data'][i]['again_explain'].length > 0) {
								html += '<p><span class="content-left">追评回复:</span> <span class="evaluate_reply content">'+data['data'][i]['again_explain']+'</span></p></td>';
								html += '<td style="background: white;"><div style="text-align: center;"><a href="javascript:;" data-placement="bottom" data-original-title="回复"><span class="edit" onclick="replyevaluateAgain('+data['data'][i]['id'] +',this)"><i class="icon-edit" style="width: initial;"></i>回复</span></a>';
							}else{
								html += '<td style="background: white;"><div style="text-align: center;"><a href="javascript:;" data-placement="bottom" data-original-title="回复"><span class="edit" onclick="replyevaluateAgain('+data['data'][i]['id'] +',this)"><i class="icon-edit" style="width: initial;"></i>回复</span></a>';
							}
						}
						$("#productTbody").append(html);
					}
				}else {
					html = '<tr align="center"><td colspan="6" style="text-align: center;">暂无符合条件的数据记录</td></tr>';
					
				}
				$("#list").html(html);
				var totalpage = $("#page_count").val();
				if (totalpage == 1) {
					changeClass("all");
				}
				var $html = pagenumShow(jumpNumber,totalpage,{$pageshow})
				$("#pageNumber").append($html);
				img_lazyload();
			}
		});
	}
	
	//隐藏商品分组
	function hideEditGroup(){
		$("#editGroup").popover("hide");
	}

	function hideSetRecommend(){
		$("#setRecommend").popover("hide");
	}
	
	$("#search_text").keypress(function(e){
		if(e.keyCode == 13){
			LoadingInfo(1);
		}
	});
	
	function batchDelete() {
		var evaluate_id= new Array();
		$("#productTbody input[type='checkbox']:checked").each(function() {
			if (!isNaN($(this).val())) {
				evaluate_id.push($(this).val());
			}
		});
		if(evaluate_id.length ==0){
			$( "#dialog" ).dialog({
				buttons: {
					"确定,#0059d6,#fff": function() {
						$(this).dialog('close');
					}
				},
				contentText:"请选择需要操作的记录",
				title:"消息提醒",
			});
			return false;
		}
		deleteEvaluate(evaluate_id);
	}

	// 删除
	function deleteEvaluate(evaluate_id){
		$( "#dialog" ).dialog({
			buttons: {
				"确定": function() {
					$(this).dialog('close');
					$.ajax({
						type : "post",
						url : "{:__URL('PLATFORM_MAIN/goods/deleteevaluateajax')}",
						data : { "evaluate_id" : evaluate_id.toString() },
						dataType : "json",
						success : function(data) {
							if(data['code'] > 0){
								LoadingInfo($("#pageNumber .active").html());
								showMessage('success', data['message']);
							}else{
								showMessage('error', data['message']);
							}
						}
					});
				},
				"取消,#f5f5f5,#666" : function(){
					$(this).dialog('close');
				}
			},
			contentText:"你确定删除吗？",
			title:"消息提醒"
		});
	}

	//回复 弹出框
	function replyevaluate(evaluate_id, event){
		var evaluate_content = $(event).parents('tr').find('.evaluate_content').html();
		var evaluate_reply = $(event).parents('tr').find('.evaluate_reply').html();
		if(evaluate_reply == undefined){
			evaluate_reply = '';
		}
		$("#replyType").val(1);
		$("#myModalLabel").text("评价回复");
		$("#myModaltype").text("评价内容：");
		$("#evaluate").modal('show');
		$("#evaluate_id").val(evaluate_id);
		$("#evaluate_content").html(evaluate_content);
		$("#evaluate_reply").text(evaluate_reply);
	}

	function replyevaluateAgain(evaluate_id, event){
		var evaluate_content = $(event).parents('tr').find('.evaluate_content').html();
		var evaluate_reply = $(event).parents('tr').find('.evaluate_reply').html();
		if(evaluate_reply == undefined){
			evaluate_reply = '';
		}
		$("#replyType").val(2);
		$("#myModalLabel").text("追评回复");
		$("#myModaltype").text("追评内容：");
		$("#evaluate").modal('show');
		$("#evaluate_id").val(evaluate_id);
		$("#evaluate_content").html(evaluate_content);
		$("#evaluate_reply").text(evaluate_reply);
	}

	// 回复提交
	function replyevaluateAjax(){
		var evaluate_id = $("#evaluate_id").val();
		var evaluate_reply = $("#evaluate_reply").val();
		var replyType = $("#replyType").val(); //1为评价回复 2为追评回复
		
		$.ajax({
			type : "post",
			url : "{:__URL('PLATFORM_MAIN/goods/replyevaluateajax')}",
			data : {
				"evaluate_id" : evaluate_id, 
				"evaluate_reply" : evaluate_reply,
				"replyType" : replyType
			},
			success : function(data) {
				//console.log(data);return;
				if(data['code'] > 0){
					showMessage('success', data['message']);
					LoadingInfo($("#pageNumber .active").html());
				}else{
					showMessage('error', data['message']);
				}
				$("#evaluate").modal('hide');
			}
		});
	}

	//设置显示状态
	function setEvaluteShowStatuAjax(evaluate_id){
		$.ajax({
			type : "post",
			url : "{:__URL('PLATFORM_MAIN/goods/setevaluteshowstatuajax')}",
			data : {"evaluate_id" : evaluate_id},
			success : function(data) {
				if(data['code'] > 0){
					LoadingInfo($("#pageNumber .active").html());
				}else{
					showMessage('error', data['message']);
				}
			}
		});
	}

	document.onkeydown = function(e){ 
		var ev = document.all ? window.event : e;
		if(ev.keyCode==13) {
			LoadingInfo(1);
		}
	}

	// 点击显示更多搜索
	$(".more-search").click(function(){
		$(".more-search-container").slideToggle();
	})
</script>
{/block}
